package com.nanshenycd.controller.front;

import com.nanshenycd.dao.FeedbackDao;
import com.nanshenycd.pojo.Feedback;
import com.nanshenycd.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
@Api(description  = "博客反馈接口")
public class FeedbackController {

    @Autowired
    private FeedbackDao feedbackDao;

    @GetMapping(value = "/reject")
    @ApiOperation(value = "首页默认路径渲染")
    public String hello(){
        return "feedback";
    }

    @PostMapping(value = "/saveFeedback")
    @ApiOperation(value = "保存反馈信息")
    public String saveFeedback(Feedback feedback, User user, Model model){
        int i = feedbackDao.saveFeedback(feedback);
        if(i!=-1){
            model.addAttribute("msg","保存成功");
            return "feedbackSuccess";
        }else{
            model.addAttribute("msg","保存失败");
        }
        return "/error/error";
    }
}
